package codeTop;

public class q34 {
    public int[] searchRange(int[] nums, int target) {
        if (nums.length == 0) {
            return new int[]{-1,-1};
        }
        int l = binarySearch(nums, target);
        int r = binarySearch(nums, target + 1);
        int[] res = new int[2];
        res[0] = l<nums.length&&nums[l]==target?l:-1;
        res[1] = l<nums.length&&nums[l]==target?r-1:-1;
        return res;
    }
    int binarySearch(int[] nums,int target){
        int l = 0,r = nums.length;
        while (l < r) {
            int mid = l+(r-l)/2;
            if (nums[mid] < target) {
                l = mid+1;
            }else {
                r = mid;
            }
        }
        return l;
    }
}
